﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Campus.Main.Basic.Settings;
using Campus.Report.ReportForm;
using Microsoft.Reporting.WinForms;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic
{
    public partial class BolumInsertForm : DefaultForm
    {
        public BolumInsertForm()
        {
            InitializeComponent();
        }

        private void BolumInsertForm_Load(object sender, EventArgs e)
        {
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            aToDb.AddItemDBGridView(dataGridView1,Query.OnKayit);
            toolStripStatusLabel1.Text ="Ön kayıt olan öğrencilerin sayısı="+ aToDb.SelectField("select count(*) from onmaintable");
        }

        protected void button1_Click(object sender, EventArgs e)
        {
             ReportForm f=new ReportForm();
            f.reportViewer1.ProcessingMode=ProcessingMode.Local;
            f.reportViewer1.LocalReport.ReportPath = "ReportTemplate/OnkayitReport.rdlc";
            f.reportViewer1.LocalReport.DataSources.Clear();
            f.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",dataGridView1.DataSource));
            f.ShowDialog();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            string query = Query.OnKayit;
            if (radioButton1.Checked)
            {
                aToDb.AddItemDBGridView(dataGridView1,query);
                toolStripStatusLabel1.Text = "Ön kayıt olan öğrencilerin sayısı=" + aToDb.SelectField("select count(*) from onmaintable");
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            string query = Query.OnKayit+" and a.pol_id=1";
            if (radioButton2.Checked)
            {
                aToDb.AddItemDBGridView(dataGridView1, query);
                toolStripStatusLabel1.Text = "Ön kayıt olan öğrencilerin sayısı=" + aToDb.SelectField("select count(*) from onmaintable where pol_id=1");
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            string query = Query.OnKayit + " and a.pol_id=2";
            if (radioButton3.Checked)
            {
                aToDb.AddItemDBGridView(dataGridView1, query);
                toolStripStatusLabel1.Text = "Ön kayıt olan öğrencilerin sayısı=" + aToDb.SelectField("select count(*) from onmaintable where pol_id=2");
            }
        }

        protected virtual void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
                return;
            List<string> data = new List<string>();
            ControlComponent.AddToList(data, dataGridView1, e, 0);
            Kayit f = new Kayit(data[0]);
            f.FormClosed += child_FormClosed;
            Hide();
            f.ShowDialog();
        }

        protected void child_FormClosed(object sender, FormClosedEventArgs e)
        {
            Close();
        }

    }
}
